/*Copyright 2016 Adobe Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. AIG. Copyright © American International Group, Inc. All rights reserved. emailto:contact AT dmp-support@aig.com This HTML file supports the AEM touch UI dialog License as published by the AIG; either 2 Peach Tree Hill Rd, Livingston, NJ 07039. This file includes all the search result pagination scripts */ /* * This funciton is used in the search components * which implement pagination, news, product search * Ajax call which retrives partial search results. * The code is being used from AIG international code base. * */ const DATA_CURRNODE = 'data-currnode'; const FILTER_RESULT = '#filter-results'; const DATA_DETAILS = '.data-div'; var PARTIAL_CRITERIA_PARAM = '?criteria='; var PARTIAL_BATCH_PARAM = 'batch='; var selVal = $('#filter-dropdown').val(); var batchNo = 0; /*Function to display articles based on Filter Selected*/ $(document).ready(function () { const FILTER_DROPDOWN = '#filter-dropdown'; $(FILTER_DROPDOWN).on('change', function () { batchNo = 0; selVal = $(FILTER_DROPDOWN).val(); const currNode = $(FILTER_DROPDOWN).attr(DATA_CURRNODE); var targetUrl = currNode.concat(PARTIAL_CRITERIA_PARAM, selVal); $.ajax({ type: 'GET', url: targetUrl, success: function (response) { const sanitizedResponse = $.parseHTML($.trim(response), null, false); //$(FILTER_RESULT).html(sanitizedResponse); sanitizedResponse.filter(function(item) { if (item.classList != undefined) { if (item.classList.contains('cmp-filter-article__results')) { $(FILTER_RESULT).html($(item)); } if (item.classList.contains('data-div')) { $(DATA_DETAILS).html($(item)); } } }); } }); }); }); /*Function to display articles based on Filter Selected--Ends*/ /*Function to Update Filter data by Lazy Loading*/ $(window).on('load', function () { if($('.filter').length) { updateFilterData(); $('.filter').append('
'); } }); function updateFilterData() { batchNo = 0; var totalBatches = 0; //scroll function $(window).on('scroll', function () { var totalItems = parseInt($('.cmp-filter-results__total').attr('value')); var resultItems = parseInt($('.cmp-filter-results__count').attr('value')); //if cards are to be loaded from backend, calculate no. of requests if (resultItems != 0) totalBatches = Math.ceil((totalItems - resultItems) / resultItems); //if loaded cards are less then total cards, make a request and show loader icon if ($(window).scrollTop() >= $('.filter').offset().top + $('.filter').outerHeight() - window.innerHeight) { if (batchNo < totalBatches && resultItems < totalItems && resultItems > 0) { batchNo++; var criteria = PARTIAL_CRITERIA_PARAM.concat(selVal); var batch = PARTIAL_BATCH_PARAM.concat(batchNo); const currNode = $(FILTER_RESULT).attr(DATA_CURRNODE); if ($('.filter .custom-select').length) { var targetUrl = currNode.concat(criteria, '&', batch); } else { var batchParam = '?batch='; batch = batchParam.concat(batchNo); var targetUrl = currNode.concat(batch); } $.ajax({ type: 'GET', url: targetUrl, dataType: 'html', beforeSend: function () { $('.cmp-filter__loader').show(); }, complete: function () { $('.cmp-filter__loader').hide(); }, success: function (response) { const nextBatch = $.parseHTML($.trim(response), null, false); nextBatch.filter(function(item) { if (item.classList != undefined) { if (item.classList.contains('cmp-filter-article__results')) { var listItems = item.querySelectorAll('li.cmp-filter-article__item'); $('ul.cmp-filter-article__results').append(listItems); } } }); } }); } } }); } /*Function to Update Filter data by Lazy Loading--Ends*/